<?php
/**
 * Created by PhpStorm.
 * User: 郑合达
 * Date: 2019/2/20
 * Time: 14:24
 */

namespace app\admin\controller;


use think\Controller;
use app\model\UserModel;
use app\model\MenuModel;
use app\model\AppUserModel;
class Index extends Controller
{
    public function index()
    {
        $this->redirect('login');
    }
    //注册页面
    public function reg(){
        return view('reg');
    }
    //登陆页面
    public function regData(){
        return view('login');
    }
    //登陆页面
    public function login(){
        return view('login');
    }
    /*
    * 登陆
    */
    public function loginData()
    {
        $getData=input('post.');
        $where=['phone'=>$getData['user_name'],'password'=>encryptPass($getData['user_pass'])];
        $getUser=AppUserModel::where($where)->find();//用户信息
        $name = MenuModel::where('user_id',$getUser['id'])->value('name');
        
        if (!$getUser){
            $this->error('请检查信息是否正确');
        }
		//判断用户分组表有没有该用户
        if(!$name){
            $data['name']=$getUser['nickname'];
            $data['follow_id']=70;
            $data['user_id'] =$getUser['id'];
            $res = MenuModel::create($data); //新增
        }
        //可以登陆  session信息
        session('name',$name); //设备昵称;
        session('user',$getUser);
        $this->redirect('User/menu');
    }
    /*
     * 退出登陆
     */
    public function outLogin()
    {
        session_start();
        session_destroy();
        $this->redirect('Index/login');
    }
}